﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Model {
    class TextData {
        public static string Base64(string str) => Convert.ToBase64String(Encoding.UTF8.GetBytes(str));
        public static string Debase64(string str) => Encoding.UTF8.GetString(Convert.FromBase64String(str));
        public static string MD5(string str) => Crypto(new MD5CryptoServiceProvider(), str);
        public static string SHA1(string str) => Crypto(new SHA1CryptoServiceProvider(), str);
        public static string SHA256(string str) => Crypto(new SHA256CryptoServiceProvider(), str);
        public static string SHA384(string str) => Crypto(new SHA384CryptoServiceProvider(), str);
        public static string SHA512(string str) => Crypto(new SHA512CryptoServiceProvider(), str);
        private static string Crypto(HashAlgorithm HashMethod, string str) => BitConverter.ToString(HashMethod.ComputeHash(Encoding.UTF8.GetBytes(str))).Replace("-", "").ToUpper();
    }
}
